package org.linlinjava.litemall.wx.task;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.linlinjava.litemall.core.task.Task;
import org.linlinjava.litemall.core.util.BeanUtil;
import org.linlinjava.litemall.db.domain.LitemallMemberOrder;
import org.linlinjava.litemall.db.service.LitemallMemberOrderService;

/**
 * @author piao
 */
public class MemberOrderUnpaidTask extends Task {
    private final Log logger = LogFactory.getLog(MemberOrderUnpaidTask.class);
    private int memberOrderId = -1;

    public MemberOrderUnpaidTask(Integer memberOrderId, Long delayInMilliseconds) {
        super("MemberOrderUnpaidTask-" + memberOrderId, delayInMilliseconds);
        this.memberOrderId = memberOrderId;
    }

    @Override
    public void run() {
        logger.info("系统开始处理延时任务---会员未支付订单");
        LitemallMemberOrderService memberOrderService = BeanUtil.getBean(LitemallMemberOrderService.class);
        LitemallMemberOrder memberOrder = memberOrderService.findById(this.memberOrderId);
        if (memberOrder == null) {
            return;
        }
        memberOrderService.delete(this.memberOrderId);
        logger.info("系统结束处理延时任务---会员未支付订单---\" + this.orderId ");
    }
}
